package com.iceengine.j3d.objects;

/**
 * This class is used to hold vertex variables.
 * @author penguin
 */
import org.lwjgl.util.vector.Vector3f;
import org.lwjgl.util.vector.Vector2f;
import org.lwjgl.opengl.GL11;

public class Vertex {
    private Vector3f Coordinates;
    private Vector2f MappingCoordinates;
    /**
     * Initializes the vertex.
     * @param coordinates Coordinates where the vertex is located.
     * @param mappingcoordinates UV-Mapping coordinates.
     */
    public Vertex(Vector3f coordinates, Vector2f mappingcoordinates)
    {
        Coordinates = coordinates;
        MappingCoordinates = mappingcoordinates;
    }

    /**
     * This uses opengl to draw the vertex.
     */
    public void drawVertex()
    {
        if(isMappingAvailable())
            GL11.glTexCoord2f(MappingCoordinates.x, MappingCoordinates.y);
        
        GL11.glVertex3f(Coordinates.x, Coordinates.y, Coordinates.z);
    }

    /**
     * Checks if UV-Mappingcoordinates are available.
     * @return True if mappingcoordinates are available, false if not.
     */
    public boolean isMappingAvailable()
    {
        if(MappingCoordinates != null)
            return true;
        else
            return false;
    }

    /**
     * Gets the X-Coordinate of the vertex location.
     * @return The coordinate.
     */
    public float getX()
    {
        return Coordinates.x;
    }
    /**
     * Gets the Y-Coordinate of the vertex location.
     * @return The coordinate.
     */
    public float getY()
    {
        return Coordinates.y;
    }
    /**
     * Gets the Z-Coordinate of the vertex location.
     * @return The coordinate.
     */
    public float getZ()
    {
        return Coordinates.z;
    }
    /**
     * Gets the U-Coordinate of the mappingcoordinates.
     * @return The coordinate.
     */
    public float getU()
    {
        return MappingCoordinates.x;
    }
    /**
     * Gets the V-Coordinate of the mappingcoordinates.
     * @return The coordinate.
     */
    public float getV()
    {
        return MappingCoordinates.y;
    }
}
